(function(){
  var ua = window.navigator.userAgent.toLocaleLowerCase();
  if (ua.indexOf('iphone') > -1 || ua.indexOf('android') > -1) {
    var _mode = 'mobile',
      _dpr = window.devicePixelRatio || 1,
      _width = window.screen.width * _dpr;
  } else {
    var _mode = 'pc',
      _dpr = 1,
      _htmlWidth = window.outerWidth || 540,
      _width = _htmlWidth < 540 ? _htmlWidth : 540;
      // _width = 375;
  }

  var _rem = _width / 10,
    _meta = document.createElement("meta");
  _meta.setAttribute("name", "viewport");
  _meta.setAttribute("content", "width="+_width+",initial-scale="+(1/_dpr)+",maximum-scale="+(1/_dpr)+",minimum-scale="+(1/_dpr)+",user-scalable=no");
  document.head.appendChild(_meta);
  document.documentElement.style.fontSize = _rem + 'px';

  /*
    三星等一些手机设置了系统字体大小之后会影响rem的设置
    测试中遇到某款三星手机，系统字体设置成"小"时，原本预期 1rem = 根字体大小，然后实际出现 1rem = 根字体大小 * 0.85 的情况
    故：根据此情况，需要重置 根字体大小，以达到不受系统字体大小影响
  */
  document.addEventListener('DOMContentLoaded', function(){
    document.body.style.width = '10rem';
    _rem = _rem * _width / document.body.clientWidth;
    document.documentElement.style.fontSize = _rem + 'px';
  }, false);

  if (_mode == 'mobile') {
    window.tap = 'tap';
    window.touchstart = "touchstart";
    window.touchmove = "touchmove";
    window.touchend = "touchend";
  } else {
    window.tap = 'click';
    window.touchstart = "mousedown";
    window.touchmove = "mousemove";
    window.touchend = "mouseup";
  }
}());